//https://leetcode.cn/problems/implement-stack-using-queues/
// Created by ade on 2022/7/25.
//

class MyStack {
public:
    queue<int> in;
    queue<int> out;
    MyStack() {

    }

    void push(int x) {
        in.push(x); // 1,2,3,4
    }

    int pop() {
        while(in.size() != 1){
            out.push(in.front());
            in.pop();
        }
        int top = in.front();
        in.pop();
        while(!out.empty()){
            in.push(out.front());
            out.pop();
        }
        return top;
    }

    int top() {
        return in.back();
    }

    bool empty() {
        return in.empty();
    }
};